package com.healthy.education.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.healthy.common.log.annotation.Log;
import com.healthy.common.log.enums.BusinessType;
import com.healthy.common.security.annotation.RequiresPermissions;
import com.healthy.education.domain.HealthLectures;
import com.healthy.education.service.IHealthLecturesService;
import com.healthy.common.core.web.controller.BaseController;
import com.healthy.common.core.web.domain.AjaxResult;
import com.healthy.common.core.utils.poi.ExcelUtil;
import com.healthy.common.core.web.page.TableDataInfo;

/**
 * 健康讲座Controller
 * 
 * @author 束伟
 * @date 2024-03-29
 */
@RestController
@RequestMapping("/HealthLectures")
public class HealthLecturesController extends BaseController
{
    @Autowired
    private IHealthLecturesService healthLecturesService;

    /**
     * 查询健康讲座列表
     */
    @RequiresPermissions("education:HealthLectures:list")
    @GetMapping("/list")
    public TableDataInfo list(HealthLectures healthLectures)
    {
        startPage();
        List<HealthLectures> list = healthLecturesService.selectHealthLecturesList(healthLectures);
        return getDataTable(list);
    }

    /**
     * 导出健康讲座列表
     */
    @RequiresPermissions("education:HealthLectures:export")
    @Log(title = "健康讲座", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HealthLectures healthLectures)
    {
        List<HealthLectures> list = healthLecturesService.selectHealthLecturesList(healthLectures);
        ExcelUtil<HealthLectures> util = new ExcelUtil<HealthLectures>(HealthLectures.class);
        util.exportExcel(response, list, "健康讲座数据");
    }

    /**
     * 获取健康讲座详细信息
     */
    @RequiresPermissions("education:HealthLectures:query")
    @GetMapping(value = "/{lectureId}")
    public AjaxResult getInfo(@PathVariable("lectureId") Long lectureId)
    {
        return success(healthLecturesService.selectHealthLecturesByLectureId(lectureId));
    }

    /**
     * 新增健康讲座
     */
    @RequiresPermissions("education:HealthLectures:add")
    @Log(title = "健康讲座", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HealthLectures healthLectures)
    {
        return toAjax(healthLecturesService.insertHealthLectures(healthLectures));
    }

    /**
     * 修改健康讲座
     */
    @RequiresPermissions("education:HealthLectures:edit")
    @Log(title = "健康讲座", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HealthLectures healthLectures)
    {
        return toAjax(healthLecturesService.updateHealthLectures(healthLectures));
    }

    /**
     * 删除健康讲座
     */
    @RequiresPermissions("education:HealthLectures:remove")
    @Log(title = "健康讲座", businessType = BusinessType.DELETE)
	@DeleteMapping("/{lectureIds}")
    public AjaxResult remove(@PathVariable Long[] lectureIds)
    {
        return toAjax(healthLecturesService.deleteHealthLecturesByLectureIds(lectureIds));
    }
}
